<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>闭包存储值</title>
</head>
<body>
<script>
    // 闭包私有变量
    let Person = (function(){
        var _gender = '';
        function P(name,gender) {
            this.name = name;
            _gender = gender;
        }
        P.prototype.getGender = function() {
            return _gender;
        }
        return P;
    })();
    let P1 = new Person('小刘','男');
    console.log(P1);// 在当前构造函数new出来的对象是没法获取到性别的值的
    console.log(P1.getGender());// 通过自定义的方法来访问闭包的私有变量
</script>
</body>
</html>